<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

define('START', true);	

session_start();	
	
# set error checking levels #	
	# enable these lines when site is o be deployed #	
	ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    //ini_set('log_errors', 'On');
    //ini_set('error_log', '/usr/local/apache/logs/error_log');
	
	#############################
	# include some needed files #
	#############################
		$absRoot = '../../';
		include($absRoot . 'lib/XAJAX/xajax_core/xajax.inc.php');
		include($absRoot . 'src/ClientHandle.php');

	$id = $_GET["client_id"];

	$client = new ClientHandle();

	$ProfileArray=$client->getClientProfile($id);

	$CourseName=$ProfileArray["client_coursename"];
	$CourseCode=$ProfileArray["client_coursecode"];

	
# instantiate predifined classes #											
	$xajax = new xajax();

	$xajax->registerFunction("editClientCourse");
	
	function editClientCourse($coursename, $coursecode, $id) {
		$statusresponse = new xajaxResponse();
		
		# check if the fields are empty
			if (empty($coursename) || empty($coursecode)) {
				$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br /> Not updating..');
			}
			else {

				include($absRoot . 'src/ClientHandle.php');
			
			$client = new ClientHandle();

			$ProfileArray=$client->getClientProfile($id);

			$CourseName=$ProfileArray["client_coursename"];
			$CourseCode=$ProfileArray["client_coursecode"];
				
					if (strcmp($CourseName, $coursename)==0 && strcmp($CourseCode, $coursecode)==0) {
						$statusresponse->assign('Status', 'innerHTML', 'No changes is made.<br /> Not updating..');
					}
					elseif ($id != '') {
							
						$result = $client->setProfileValue('client_coursecode', $coursecode, $id);
						$result = $client->setProfileValue('client_coursename', $coursename, $id);
						
						if($result == true)
						$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br /> Not updating..');
						else
						$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br />Not updating..');	
					}
			
			}
			
								
		return$statusresponse;
	}
	$xajax->processRequest();	

	//print_r($result);
?>

<html>
<head>
	<script type="text/javascript" src="../../lib/XAJAX/xajax_js/xajax_core.js" />
	<link rel="stylesheet" type="text/css" href="../../lib/YUI/yui/build/fonts/fonts-min.css" />
	<?php $xajax->printJavaScript(); ?>
</head>
<body>											


<form id="EditClientCourse" action="#" method='post'>
<table>
	
	<tr>
	<td>
	Course Name:</td>
	<td>
	<input type=text id="CourseName" value="<?php echo $CourseName;?>"></input>
	</td>
	</tr>
	<tr>
	<td>
	Course Code:</td>
	<td>
	<input type=text id="CourseCode" value="<?php echo $CourseCode;?>"></input>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	<td>
	<input type=button id="Update" value="Update" onclick="xajax_editClientCourse(document.getElementById('CourseName').value, document.getElementById('CourseCode').value, <?php echo $id;?>);"></input>
	<input type=reset id="Reset" value="Reset"></input>
	</td>
	</tr>
	
	
</table>

</form>
<div id='Status'></div>

</body>

</html>